package com.dashuai.modbus.util;

import com.serotonin.modbus4j.exception.ModbusInitException;

/**
 * <p>
 *
 * </p>
 *
 * @author 苏州QM
 * @date 2024/4/30
 */
public class CheckUtil {

    public static void checkIPAndPort(String ip, int port) throws ModbusInitException {

        String regex = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
        if (!ip.matches(regex)) {
            throw new ModbusInitException("The tcp ip address format is incorrect");
        }

        if (port < 0 || port > 65535) {
            throw new ModbusInitException("The tcp port number is out of range");
        }
    }
}
